package com.shujia.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class PhoenixJDBC {
    public static void main(String[] args) throws Exception {
        //注册驱动
        Class.forName("org.apache.phoenix.jdbc.PhoenixDriver");

        //创建与phoenix连接对象
        Connection conn = DriverManager.getConnection("jdbc:phoenix:master,node1,node2:2181");

        PreparedStatement prep = conn.prepareStatement("select /*+ INDEX(DIANXIN DIANXIN_INDEX) */  * from DIANXIN where end_date = ? and start_date = ?");

        prep.setString(1,"20180503154014");
        prep.setString(2,"20180503154614");

        ResultSet resultSet = prep.executeQuery();
        while (resultSet.next()){
            /*
                 mdn VARCHAR ,
                 start_date VARCHAR ,
                 end_date VARCHAR ,
                 county VARCHAR,
                 x DOUBLE ,
                 y  DOUBLE,
                 bsid VARCHAR,
                 grid_id  VARCHAR,
                 biz_type VARCHAR,
                 event_type VARCHAR ,
                 data_source VARCHAR ,
             */
            String mdn = resultSet.getString("mdn");
            String start_date = resultSet.getString("start_date");
            String end_date = resultSet.getString("end_date");
            String county = resultSet.getString("county");
            double x = resultSet.getDouble("x");
            double  y = resultSet.getDouble("y");
            String bsid = resultSet.getString("bsid");
            String grid_id = resultSet.getString("grid_id");
            String biz_type = resultSet.getString("biz_type");
            String event_type = resultSet.getString("event_type");
            String data_source = resultSet.getString("data_source");

            System.out.println(mdn+","+start_date+","+end_date+","+county+","+x+","+y+","+bsid
                    +","+grid_id+","+biz_type+","+event_type+","+data_source);
        }

        //释放资源
        prep.close();
        conn.close();

    }
}
